<?php
if (count($rows) > 0) {
$view_report_title_disabled = BUtils::T('special_report_not_ready_eg');
	
$reach_lbl = '<span class="" rel="tipsy" title="'.BUtils::T('special_report_reach_eg').'">' . BUtils::T('special_report_reach_lbl') . '</span>';
$clicks_lbl = '<span class="" rel="tipsy" title="'.BUtils::T('special_report_clicks_eg').'">' . BUtils::T('special_report_clicks_lbl') . '</span>';
$notifications_lbl = '<span class="" rel="tipsy" title="'.BUtils::T('special_report_notifications_eg').'">' . BUtils::T('special_report_notifications_lbl') . '</span>';
$redeem_lbl = '<span class="" rel="tipsy" title="'.BUtils::T('special_report_redeems_eg').'">' . BUtils::T('special_report_redeems_lbl') . '</span>';
?>
<table class="table table-striped">
	<tbody>
<?php foreach ($rows as $r) {
	//set offer picture
	$url_thumb_default = Yii::app()->baseUrl . '/img/default_special_thumb.png';
	$url_picture_default = Yii::app()->baseUrl . '/img/default_special_picture.png';
	$url_thumb = empty($r['url_picture']) ? $r['url_offer_img'] : $r['url_picture'];
	if (!empty($url_thumb)) {
		$url_thumb = BUtils::GetOfferThumbUrl($url_thumb);
		$url_picture = BUtils::GetOfferPictureUrl(str_replace('thumb_', '', $url_thumb));
	} else {
		$url_thumb = $url_thumb_default;
		$url_picture = $url_picture_default;
	}
	
	//set price, discount or highlight
	$highlight = $del_price = '';
	if (!empty($r['price'])) {
		$highlight = Yii::app()->locale->numberFormatter->formatCurrency($r['price'], 'EUR');
		if (!empty($r['value'])) {
			$value = Yii::app()->locale->numberFormatter->formatCurrency($r['value'], 'EUR');
			$del_price = '<small><s class="gray">'.$value.'</s></small>';
		}
	} elseif (!empty($r['discount'])) {
		$highlight = MerchantObject::formatDiscount($r['discount']);
	}
	
	//offer content
	$content = $body = strip_tags(trim($r['content']));
	if (strlen($content) > 108) {
		$match = null;
		if (preg_match('/^.{1,108}\b/s', $body, $match)) {
			$content = $match[0] . ' ...';
		}
	}
	
	//set expired or upcoming offer style
	$now = time();
	if ($now < $r['uts_start_date']) {
		$ex_days = 0;//pending status
	} elseif ($now > $r['uts_end_date']) {
		$ex_days = round(($r['uts_end_date'] - $r['uts_start_date']) / 3600 / 24);
	} else {
		$ex_days = round((time() - $r['uts_start_date']) / 3600 / 24);
	}
	if ($ex_days === 0) {
		//pending status
		$reach = $clicks = $notifications = $spread = $redeems = '-';
	} else {
		$clicks = round($r['clicks']);
		$notifications = round($r['notifications']);
		$spread = round($r['spread']);
		$redeems = round($r['redeems']);
		$reach = round($r['reach']);
		if ($reach < 1) {
			$reach = $clicks = $notifications = $spread = $redeems = '-';
		}
	}
?>
<tr>
	<td style="width:50px;">
		<a href="<?php echo Yii::app()->createUrl('/offer/preview', array('id'=>$r['id'])) ?>" class="popup-btn">
			<img class="img-polaroid" style="width:48px;" src="<?php echo $url_thumb; ?>" alt="" onError="this.onerror=null;this.src='<?php echo $url_thumb_default; ?>';" />
		</a>
	</td>
	<td>
		<h4 class="orange"><?php echo $highlight; ?> <?php echo $del_price; ?></h4>
		<a href="<?php echo Yii::app()->createUrl('/offer/preview', array('id'=>$r['id'])) ?>" class="popup-btn"><?php echo $content; ?></a>
	</td>
	<td style="width:130px;font-size:11px;line-height:13px;text-align:center;">
<?php if ($reach == '-') { ?>
		<div class="center" style="color:#cde;">
			<i class="icon-gears icon-4x"></i>
		</div>
		<div class="hr hr4"></div>
		<span style="color:#888;"><?php echo $view_report_title_disabled; ?></span>
<?php } else { ?>
		<a href="<?php echo Yii::app()->createUrl('/offer/reportDaily', array('id'=>$r['id'])) ?>" class="popup-btn">
			<div class="row-fluid">
				<div class="span6 pointer"><?php echo $reach; ?><br /><?php echo $reach_lbl; ?></div>
				<div class="span6 pointer"><?php echo $clicks; ?><br /><?php echo $clicks_lbl; ?></div>
			</div>
			<div class="hr hr4"></div>
			<div class="row-fluid">
				<div class="span6 pointer"><?php echo $notifications; ?><br /><?php echo $notifications_lbl; ?></div>
				<div class="span6 pointer"><?php echo $redeems; ?><br /><?php echo $redeem_lbl; ?></div>
			</div>
		</a>
<?php } ?>
	</td>
</tr>
<?php
} ?>
	</tbody>
</table>
<script type="text/javascript">
$(function() {
	$('.popup-btn').facebox({
		loadingImage: '<?php echo Yii::app()->baseUrl ?>/img/ajax-loaders/ajax-loader-4.gif',
		closeImage: '<?php echo Yii::app()->baseUrl ?>/img/btn-close.png',
		overlayClose:true, width:360
	});
});
</script>
<?php
} else {
	//url
	$action_btn = '<a href="' . Yii::app()->createUrl('/offer/form') . '">'.BUtils::T('create_offer_lbl').'</a>';
?>
<div class="no-offer">
	<div class="well well-large gray">
		<h3 class=""><?php echo BUtils::T('offers_no_item_lbl') ?></h3>
		<p><?php echo BUtils::T('offers_not_missing_msg') ?></p>
		<p><?php echo BUtils::T('offers_no_item_action_msg', array('{action}'=>$action_btn)) ?></p>
	</div>
</div>
<?php
}